// manager.go
package main

import (
	"encoding/json"
	"fmt"
)

type numberInfo struct {
	AppId     string   `json:"appId"`
	ReqId     string   `json:"requestId"`
	ProvId    string   `json:"providerId"` //填25
	CompanyId string   `json:"enterpriseId"`
	Numbers   []string `json:"numbers"`
}

type enterpriseInfo struct {
	Name          string `json:"enterpriseName"`            //企业名称
	Province      string `json:"provinceCode"`              //省份代码
	IdType        string `json:"enterpriseCertificateType"` //证件类型
	IdNum         string `json:"certificateNo"`             //证件号
	Addr          string `json:"certificateAddress"`        //地址
	Ceo           string `json:"legalPerson"`               //法人姓名
	IdUrl         string `json:"certificateURL"`            //证件下载URL
	Agent         string `json:"agentName"`                 //代办人姓名
	AgentIdType   string `json:"agentCertificateType"`      //代办人证件类型
	AgentIdNum    string `json:"agentCertificateNo"`        //代办人证件号码
	AgentTel      string `json:"agentContactTel"`           //代办人电话
	AgentPic1     string `json:"agentCertificateURL1"`      //代办人证件正面
	AgentPic2     string `json:"agentCertificateURL2"`      //代办人证件反面
	AgentPic3     string `json:"agentCertificateURL3"`      //代办人手持证件照
	AccptPic      string `json:"acceptanceURL"`             //电信入网承诺函
	EntrustLetter string `json:"entrustmentLetterURL"`      //介绍信
}

type enterpriseReq struct {
	AppId  string         `json:"appId"`
	Reqid  string         `json:"requestId"`
	ProvId string         `json:"providerId"` //固定25
	Info   enterpriseInfo `json:"jsltEnterpriseInfo"`
}

type enterpriseUpdate struct {
	AppId     string         `json:"appId"`
	Reqid     string         `json:"requestId"`
	ProvId    string         `json:"providerId"` //固定25
	CompanyId string         `json:"enterpriseId"`
	Info      enterpriseInfo `json:"jsltEnterpriseInfo"`
}

func enterpriseCreateTest() {
	pic := `http://fpsprivatesit-10053739.cosgz.myqcloud.com/cnc/2018/04/28/74001524904173-csh4443c5ab-01522225773798-826?sign=80Xga/7f2p9pyHBvJ8GTeAJRxHBhPTEwMDUzNzM5Jms9QUtJRHduWUF2YUZoOVFZVkgwSTRGamZUQWcxTWJmWU
hKQ09QJmU9MTUyMjIyNzExOCZ0PTE1MjIyMjU5MTgmcj0zMzQ0NDk2ODgmZj0vY25jLzIwMTgvMDQvMjgvNzQwMDE1MjQ5MDQxNzMtY3NoNDQ0M2M1YWItMDE1MjIyMjU3NzM3OTgtODI2JmI9ZnBzcHJpdmF0ZXNpdA==`

	var enterprise enterpriseReq

	enterprise.AppId = "65618"
	enterprise.ProvId = "25"
	enterprise.Reqid = "testenterpriseReq"

	enterprise.Info.AccptPic = pic
	enterprise.Info.Addr = "shenzhen"
	enterprise.Info.Agent = "Eric"
	enterprise.Info.AgentIdNum = "12345678"
	enterprise.Info.AgentIdType = "0"
	enterprise.Info.AgentPic1 = pic
	enterprise.Info.AgentPic2 = pic
	enterprise.Info.AgentPic3 = pic
	enterprise.Info.AgentTel = "2235678"
	enterprise.Info.Ceo = "Care"
	enterprise.Info.EntrustLetter = pic
	enterprise.Info.IdNum = "012356789"
	enterprise.Info.IdType = "0"
	enterprise.Info.IdUrl = pic
	enterprise.Info.Name = "heian.Ltd"
	enterprise.Info.Province = "GD"

	jsonReq, _ := json.Marshal(enterprise)
	resbody, err := PostJson(globalConf.callRest+"/ipcc/manager/enterpriseCreate", jsonReq)

	if nil != err {
		fmt.Print(err)
		return
	}
	fmt.Print(string(resbody))
}

func enterpriseUpDateTest() {

	var enterprise enterpriseUpdate

	enterprise.AppId = "65618"
	enterprise.ProvId = "25"
	enterprise.Reqid = "testenterpriseReq"
	enterprise.CompanyId = "1520776490686464"

	enterprise.Info.AccptPic = "https://1"
	enterprise.Info.Addr = "shenzhen"
	enterprise.Info.Agent = "Eric.Liu"
	enterprise.Info.AgentIdNum = "12345678"
	enterprise.Info.AgentIdType = "0"

	enterprise.Info.AgentTel = "22356789"
	enterprise.Info.Ceo = "Care.Liang"

	enterprise.Info.IdNum = "0123567890"
	enterprise.Info.IdType = "0"

	enterprise.Info.Name = "heian1.Ltd"
	enterprise.Info.Province = "GD"

	jsonReq, _ := json.Marshal(enterprise)
	resbody, err := PostJson(globalConf.callRest+"/ipcc/manager/enterpriseUpdate", jsonReq)

	if nil != err {
		fmt.Print(err)
		return
	}
	fmt.Print(string(resbody))
}

type enterpriseGetReq struct {
	AppId     string `json:"appId"`
	Reqid     string `json:"requestId"`
	ProvId    string `json:"providerId"` //固定25
	CompanyId string `json:"enterpriseId"`
}

func enterpriseQueryTest() {

	var company enterpriseGetReq
	company.AppId = "65618"
	company.Reqid = "testQuery"
	company.ProvId = "25"
	company.CompanyId = "1520776490686464"

	jsonReq, _ := json.Marshal(company)
	resbody, err := PostJson(globalConf.callRest+"/ipcc/manager/enterpriseQuery", jsonReq)

	if nil != err {
		fmt.Print(err)
		return
	}
	fmt.Print(string(resbody))

}

func numberAddTest() {

	var number numberInfo

	number.AppId = "65618"
	number.CompanyId = "1520776166644344"
	number.Numbers = make([]string, 0, 2)

	number.Numbers = append(number.Numbers, "0755223566")
	number.Numbers = append(number.Numbers, "0755223567")

	number.ProvId = "25"
	number.ReqId = "numberAddtest"

	jsonReq, _ := json.Marshal(number)
	fmt.Println(string(jsonReq))
	resbody, err := PostJson(globalConf.callRest+"/ipcc/manager/numberAdd", jsonReq)

	if nil != err {
		fmt.Print(err)
		return
	}
	fmt.Print(string(resbody))
}

func numberDelTest() {
	var number numberInfo

	number.AppId = "65618"
	number.CompanyId = "1520776166644344"
	number.Numbers = make([]string, 0, 2)

	number.Numbers = append(number.Numbers, "0755223566")
	number.Numbers = append(number.Numbers, "0755223567")

	number.ProvId = "25"
	number.ReqId = "numberDeltest"

	jsonReq, _ := json.Marshal(number)
	resbody, err := PostJson(globalConf.callRest+"/ipcc/manager/numberDel", jsonReq)

	if nil != err {
		fmt.Print(err)
		return
	}
	fmt.Print(string(resbody))
}
